package com.helwen.tools;

import org.apache.commons.codec.binary.Base64;
import org.junit.jupiter.api.Test;

import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 将用户名与密码  写到Authorization中
 */
public class CurlHttptool {

    @Test
    public void getCurlu() throws FileNotFoundException, IOException {
        String name="Administrator";
        String password="helwen123";
        String authString = name + ":" + password;

        System.out.println("auth string: " + authString);

        //Base64编码
        byte[] authEncBytes = Base64.encodeBase64(authString.getBytes("utf-8"));

        String authStringEnc = new String(authEncBytes);

        //Authorization格式，注意“Basic ” 有个空格
        String Authorization="Basic " + authStringEnc;

        System.out.println("Authorization:"+Authorization);


    }
}
